package com.adams.app.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.adams.app.R;
import com.adams.app.common.Global;
import com.adams.app.ui.FoodsActivity;

/**
 * @description 餐厅
 * @author ChengBin
 *
 */
public class RestaurantFragment extends Fragment {

	private static Integer[] pics = {R.drawable.chuancai, R.drawable.huoguo,
		R.drawable.shaokao, R.drawable.xiaochi, R.drawable.tianping, R.drawable.kafei,
		R.drawable.cacanting, R.drawable.dongbeicai, R.drawable.yuecai};
	private static String[] category;
	private View menuLayout;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.recommend_page, container, false);
	}


	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		initMenu(view);
	}
	
	

	/**
	 * 
	 * @description 初始化菜单
	 *
	 * @author ChengBin
	 * @param view 
	 * @date   2014年1月4日下午8:57:56
	 */
	private void initMenu(View view) {
		
		category = getResources().getStringArray(R.array.food_category);
		for (int i = 0; i < 9; i++) {
			menuLayout = view.findViewWithTag("lv_"+i);
			menuLayout.setOnClickListener(menuCliclkListener);
			menuLayout.setBackgroundResource(pics[i]);
			((TextView)menuLayout.findViewById(R.id.text)).setText(category[i]);
		}
	}
	
	//菜单点击事件
	OnClickListener menuCliclkListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			String str = v.getTag().toString();
			str = str.substring(str.length() - 1, str.length());
			str = String.valueOf(Integer.parseInt(str) + 1);
			Intent intent = new Intent(getActivity(), FoodsActivity.class);
			intent.putExtra(Global.FOOD_NAME, str);
			startActivity(intent);
		}
	};


}
